package cn.aj.basic.tdo;

import cn.aj.basic.utils.MD5Utils;
import cn.aj.basic.utils.StrUtils;
import cn.aj.user.domain.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PhoneBinderDto {
    @NotBlank(message = "绑定的手机号不能为空!")
    private String phone;
    @NotBlank(message = "手机验证码不能为空!")
    private String verifyCode;
    @NotBlank(message = "accessToken不能为空!")
    private String accessToken;
    @NotBlank(message = "openId不能为空!")
    private String openId;

    public User getUser() {
        // 盐值
        String salt = StrUtils.getComplexRandomString(32);
        // 密码
        String passwords = MD5Utils.encrypByMd5(salt + 1);
        return User.builder()
                .username(this.phone)
                .phone(this.phone)
                .salt(salt)
                .password(passwords)
                .state(1)
                .createtime(new Date())
                .build();
    }
}
